using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAnimation : MonoBehaviour
{
    private Animator animtor;
    private PlayerMovement playerMovement;
    private Rigidbody2D rb;

    int groundID;
    int hangingID;
    int crouchID;
    int speedID;
    int fallID;
    void Start()
    {
        animtor = GetComponent<Animator>();
        playerMovement = GetComponentInParent<PlayerMovement>();
        rb = GetComponentInParent<Rigidbody2D>();

        groundID = Animator.StringToHash("isOnGround");
        hangingID = Animator.StringToHash("isHanging");
        crouchID = Animator.StringToHash("isCrouching");
        speedID = Animator.StringToHash("speed");
        fallID = Animator.StringToHash("verticalVelocity");
    }

    public void Update()
    {
        animtor.SetFloat(speedID, Mathf.Abs(playerMovement.XVelocity));
        animtor.SetBool(groundID, playerMovement.isOnGround);
        animtor.SetBool(hangingID, playerMovement.isHanging);
        animtor.SetBool(crouchID, playerMovement.isCrouching);
        animtor.SetFloat(fallID, rb.velocity.y);

    }

    public void StepAudio()
    {
        AudioManager.Instance.PlayFootstepAudio();
    }

    public void CrouchStepAudio()
    {
        AudioManager.Instance.PlayCrouchFootstepAudio();
    }
}
